package com.xywl;

class Point{
    private int x;
    private int y;
    public Point(int x,int y)//构造函数
    {
        this.x=x;
        this.y=y;
    }
    public int getX(){
        return x;
    }
    public int getY(){
        return y;
    }
    public void setX(int x){
        this.x=x;
    }
    public void setY(int y)
    {
        this.y=y;
    }
    public String toString(){
        return String.format("(%d,%d)",x,y);
    }
}
//继承：一个带颜色的点
class ColorPoint extends Point{
    private String color;
    public ColorPoint(int x,int y,String color)
    {
        super(x,y);//调用副类的构造函数
        this.color=color;
    }
    public String getColor(){
        return color;
    }
    public void setColor(String color){
        this.color=color;
    }
    public String toString(){
        return String.format("(%d,%d,%s)",super.getX(),super.getY(),color);
    }
}
/*
public class Main {
    public static void main(String[] args) {
        Point point =new Point(3,4);
        point.setX(5);
        point.setY(10);        System.out.println(point.toString());
    }
}*/
/*
public class Main {
    public static void main(String[] args) {
        //ColorPoint colorPoint=new ColorPoint(3,4,"red");//变量是colorPoint类型那么它一定是Point类型
        Point colorPoint =new ColorPoint(3,4,"red");
        System.out.println(colorPoint.toString());
        System.out.println(colorPoint.getX());

    }
}*/
//多态，同一个类的同一个函数的不同行为
public class Main {
    public static void main(String[] args) {
       Point a=new Point(3,4);
       System.out.println(a.toString());
       a=new ColorPoint(4,3,"green");
        System.out.println(a.toString());
    }
}
